/**
 * 
 */
package net.loyintean.pearlshell.logcenter.jms.logger;

import javax.jms.JMSException;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

import net.loyintean.pearlshell.logcenter.jms.IJmsSender;
import net.loyintean.pearlshell.logcenter.jms.IJmsSenderFactory;
import net.loyintean.pearlshell.logcenter.model.IConfigFactory;
import net.loyintean.pearlshell.logcenter.model.impl.ILogFactory;

/**
 * 多消息队列jms日志记录器
 * 
 * @author Administrator
 */
public class MultiJmsAppender extends AppenderSkeleton {

	/**
	 * 系统名称
	 */
	private String systemName;

	private IJmsSenderFactory factory = IJmsSenderFactory.getFactory("MULTI");

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.log4j.Appender#close()
	 */
	@Override
	public void close() {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.log4j.Appender#requiresLayout()
	 */
	@Override
	public boolean requiresLayout() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent
	 * )
	 */
	@Override
	protected void append(LoggingEvent event) {
		IJmsSender sender = factory.create(IConfigFactory.FACTORY.getFactory()
				.setSystemName(systemName).build());

		try {
			sender.send(ILogFactory.build(systemName, event));
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
